{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "df6817cc",
   "metadata": {},
   "source": [
    "### 3. 字符串全排列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fc01013c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bcawef\tbcawfe\tbcaewf\tbcaefw\tbcafew\tbcafwe\tbcwaef\tbcwafe\tbcweaf\tbcwefa\tbcwfea\tbcwfae\tbcewaf\tbcewfa\tbceawf\tbceafw\tbcefaw\tbcefwa\tbcfwea\tbcfwae\tbcfewa\tbcfeaw\tbcfaew\tbcfawe\tbacwef\tbacwfe\tbacewf\tbacefw\tbacfew\tbacfwe\tbawcef\tbawcfe\tbawecf\tbawefc\tbawfec\tbawfce\tbaewcf\tbaewfc\tbaecwf\tbaecfw\tbaefcw\tbaefwc\tbafwec\tbafwce\tbafewc\tbafecw\tbafcew\tbafcwe\tbwacef\tbwacfe\tbwaecf\tbwaefc\tbwafec\tbwafce\tbwcaef\tbwcafe\tbwceaf\tbwcefa\tbwcfea\tbwcfae\tbwecaf\tbwecfa\tbweacf\tbweafc\tbwefac\tbwefca\tbwfcea\tbwfcae\tbwfeca\tbwfeac\tbwfaec\tbwface\tbeawcf\tbeawfc\tbeacwf\tbeacfw\tbeafcw\tbeafwc\tbewacf\tbewafc\tbewcaf\tbewcfa\tbewfca\tbewfac\tbecwaf\tbecwfa\tbecawf\tbecafw\tbecfaw\tbecfwa\tbefwca\tbefwac\tbefcwa\tbefcaw\tbefacw\tbefawc\tbfawec\tbfawce\tbfaewc\tbfaecw\tbfacew\tbfacwe\tbfwaec\tbfwace\tbfweac\tbfweca\tbfwcea\tbfwcae\tbfewac\tbfewca\tbfeawc\tbfeacw\tbfecaw\tbfecwa\tbfcwea\tbfcwae\tbfcewa\tbfceaw\tbfcaew\tbfcawe\tcbawef\tcbawfe\tcbaewf\tcbaefw\tcbafew\tcbafwe\tcbwaef\tcbwafe\tcbweaf\tcbwefa\tcbwfea\tcbwfae\tcbewaf\tcbewfa\tcbeawf\tcbeafw\tcbefaw\tcbefwa\tcbfwea\tcbfwae\tcbfewa\tcbfeaw\tcbfaew\tcbfawe\tcabwef\tcabwfe\tcabewf\tcabefw\tcabfew\tcabfwe\tcawbef\tcawbfe\tcawebf\tcawefb\tcawfeb\tcawfbe\tcaewbf\tcaewfb\tcaebwf\tcaebfw\tcaefbw\tcaefwb\tcafweb\tcafwbe\tcafewb\tcafebw\tcafbew\tcafbwe\tcwabef\tcwabfe\tcwaebf\tcwaefb\tcwafeb\tcwafbe\tcwbaef\tcwbafe\tcwbeaf\tcwbefa\tcwbfea\tcwbfae\tcwebaf\tcwebfa\tcweabf\tcweafb\tcwefab\tcwefba\tcwfbea\tcwfbae\tcwfeba\tcwfeab\tcwfaeb\tcwfabe\tceawbf\tceawfb\tceabwf\tceabfw\tceafbw\tceafwb\tcewabf\tcewafb\tcewbaf\tcewbfa\tcewfba\tcewfab\tcebwaf\tcebwfa\tcebawf\tcebafw\tcebfaw\tcebfwa\tcefwba\tcefwab\tcefbwa\tcefbaw\tcefabw\tcefawb\tcfaweb\tcfawbe\tcfaewb\tcfaebw\tcfabew\tcfabwe\tcfwaeb\tcfwabe\tcfweab\tcfweba\tcfwbea\tcfwbae\tcfewab\tcfewba\tcfeawb\tcfeabw\tcfebaw\tcfebwa\tcfbwea\tcfbwae\tcfbewa\tcfbeaw\tcfbaew\tcfbawe\tacbwef\tacbwfe\tacbewf\tacbefw\tacbfew\tacbfwe\tacwbef\tacwbfe\tacwebf\tacwefb\tacwfeb\tacwfbe\tacewbf\tacewfb\tacebwf\tacebfw\tacefbw\tacefwb\tacfweb\tacfwbe\tacfewb\tacfebw\tacfbew\tacfbwe\tabcwef\tabcwfe\tabcewf\tabcefw\tabcfew\tabcfwe\tabwcef\tabwcfe\tabwecf\tabwefc\tabwfec\tabwfce\tabewcf\tabewfc\tabecwf\tabecfw\tabefcw\tabefwc\tabfwec\tabfwce\tabfewc\tabfecw\tabfcew\tabfcwe\tawbcef\tawbcfe\tawbecf\tawbefc\tawbfec\tawbfce\tawcbef\tawcbfe\tawcebf\tawcefb\tawcfeb\tawcfbe\tawecbf\tawecfb\tawebcf\tawebfc\tawefbc\tawefcb\tawfceb\tawfcbe\tawfecb\tawfebc\tawfbec\tawfbce\taebwcf\taebwfc\taebcwf\taebcfw\taebfcw\taebfwc\taewbcf\taewbfc\taewcbf\taewcfb\taewfcb\taewfbc\taecwbf\taecwfb\taecbwf\taecbfw\taecfbw\taecfwb\taefwcb\taefwbc\taefcwb\taefcbw\taefbcw\taefbwc\tafbwec\tafbwce\tafbewc\tafbecw\tafbcew\tafbcwe\tafwbec\tafwbce\tafwebc\tafwecb\tafwceb\tafwcbe\tafewbc\tafewcb\tafebwc\tafebcw\tafecbw\tafecwb\tafcweb\tafcwbe\tafcewb\tafcebw\tafcbew\tafcbwe\twcabef\twcabfe\twcaebf\twcaefb\twcafeb\twcafbe\twcbaef\twcbafe\twcbeaf\twcbefa\twcbfea\twcbfae\twcebaf\twcebfa\twceabf\twceafb\twcefab\twcefba\twcfbea\twcfbae\twcfeba\twcfeab\twcfaeb\twcfabe\twacbef\twacbfe\twacebf\twacefb\twacfeb\twacfbe\twabcef\twabcfe\twabecf\twabefc\twabfec\twabfce\twaebcf\twaebfc\twaecbf\twaecfb\twaefcb\twaefbc\twafbec\twafbce\twafebc\twafecb\twafceb\twafcbe\twbacef\twbacfe\twbaecf\twbaefc\twbafec\twbafce\twbcaef\twbcafe\twbceaf\twbcefa\twbcfea\twbcfae\twbecaf\twbecfa\twbeacf\twbeafc\twbefac\twbefca\twbfcea\twbfcae\twbfeca\twbfeac\twbfaec\twbface\tweabcf\tweabfc\tweacbf\tweacfb\tweafcb\tweafbc\twebacf\twebafc\twebcaf\twebcfa\twebfca\twebfac\twecbaf\twecbfa\twecabf\twecafb\twecfab\twecfba\twefbca\twefbac\twefcba\twefcab\twefacb\twefabc\twfabec\twfabce\twfaebc\twfaecb\twfaceb\twfacbe\twfbaec\twfbace\twfbeac\twfbeca\twfbcea\twfbcae\twfebac\twfebca\twfeabc\twfeacb\twfecab\twfecba\twfcbea\twfcbae\twfceba\twfceab\twfcaeb\twfcabe\tecawbf\tecawfb\tecabwf\tecabfw\tecafbw\tecafwb\tecwabf\tecwafb\tecwbaf\tecwbfa\tecwfba\tecwfab\tecbwaf\tecbwfa\tecbawf\tecbafw\tecbfaw\tecbfwa\tecfwba\tecfwab\tecfbwa\tecfbaw\tecfabw\tecfawb\teacwbf\teacwfb\teacbwf\teacbfw\teacfbw\teacfwb\teawcbf\teawcfb\teawbcf\teawbfc\teawfbc\teawfcb\teabwcf\teabwfc\teabcwf\teabcfw\teabfcw\teabfwc\teafwbc\teafwcb\teafbwc\teafbcw\teafcbw\teafcwb\tewacbf\tewacfb\tewabcf\tewabfc\tewafbc\tewafcb\tewcabf\tewcafb\tewcbaf\tewcbfa\tewcfba\tewcfab\tewbcaf\tewbcfa\tewbacf\tewbafc\tewbfac\tewbfca\tewfcba\tewfcab\tewfbca\tewfbac\tewfabc\tewfacb\tebawcf\tebawfc\tebacwf\tebacfw\tebafcw\tebafwc\tebwacf\tebwafc\tebwcaf\tebwcfa\tebwfca\tebwfac\tebcwaf\tebcwfa\tebcawf\tebcafw\tebcfaw\tebcfwa\tebfwca\tebfwac\tebfcwa\tebfcaw\tebfacw\tebfawc\tefawbc\tefawcb\tefabwc\tefabcw\tefacbw\tefacwb\tefwabc\tefwacb\tefwbac\tefwbca\tefwcba\tefwcab\tefbwac\tefbwca\tefbawc\tefbacw\tefbcaw\tefbcwa\tefcwba\tefcwab\tefcbwa\tefcbaw\tefcabw\tefcawb\tfcaweb\tfcawbe\tfcaewb\tfcaebw\tfcabew\tfcabwe\tfcwaeb\tfcwabe\tfcweab\tfcweba\tfcwbea\tfcwbae\tfcewab\tfcewba\tfceawb\tfceabw\tfcebaw\tfcebwa\tfcbwea\tfcbwae\tfcbewa\tfcbeaw\tfcbaew\tfcbawe\tfacweb\tfacwbe\tfacewb\tfacebw\tfacbew\tfacbwe\tfawceb\tfawcbe\tfawecb\tfawebc\tfawbec\tfawbce\tfaewcb\tfaewbc\tfaecwb\tfaecbw\tfaebcw\tfaebwc\tfabwec\tfabwce\tfabewc\tfabecw\tfabcew\tfabcwe\tfwaceb\tfwacbe\tfwaecb\tfwaebc\tfwabec\tfwabce\tfwcaeb\tfwcabe\tfwceab\tfwceba\tfwcbea\tfwcbae\tfwecab\tfwecba\tfweacb\tfweabc\tfwebac\tfwebca\tfwbcea\tfwbcae\tfwbeca\tfwbeac\tfwbaec\tfwbace\tfeawcb\tfeawbc\tfeacwb\tfeacbw\tfeabcw\tfeabwc\tfewacb\tfewabc\tfewcab\tfewcba\tfewbca\tfewbac\tfecwab\tfecwba\tfecawb\tfecabw\tfecbaw\tfecbwa\tfebwca\tfebwac\tfebcwa\tfebcaw\tfebacw\tfebawc\tfbawec\tfbawce\tfbaewc\tfbaecw\tfbacew\tfbacwe\tfbwaec\tfbwace\tfbweac\tfbweca\tfbwcea\tfbwcae\tfbewac\tfbewca\tfbeawc\tfbeacw\tfbecaw\tfbecwa\tfbcwea\tfbcwae\tfbcewa\tfbceaw\tfbcaew\tfbcawe\tcost : 254us\n"
     ]
    }
   ],
   "source": [
    "// 递归实现\n",
    "#include <iostream>\n",
    "#include <algorithm> \n",
    "#include <chrono>\n",
    "void CallAllPermutation(char* perm, int from, int to){\n",
    "    if(to <= 1) return;\n",
    "    if(from == to){\n",
    "        for(int i = 0; i <= to; i++){\n",
    "            std::cout << perm[i];\n",
    "        }\n",
    "        std::cout <<\"\\t\";\n",
    "    }else{\n",
    "        for(int j = from; j <= to; j++){\n",
    "            std::swap(perm[j], perm[from]);\n",
    "            CallAllPermutation(perm, from + 1, to);\n",
    "            std::swap(perm[j], perm[from]);\n",
    "        }\n",
    "    }\n",
    "}\n",
    "auto start = std::chrono::system_clock::now();\n",
    "char arr[] = \"bcawef\";\n",
    "CallAllPermutation(arr, 0, 5);\n",
    "auto end   = std::chrono::system_clock::now();\n",
    "auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);\n",
    "std::cout <<  \"cost : \" << double(duration.count()) << \"us\" << std::endl;\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f533bce6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abcefw\tabcewf\tabcfew\tabcfwe\tabcwef\tabcwfe\tabecfw\tabecwf\tabefcw\tabefwc\tabewcf\tabewfc\tabfcew\tabfcwe\tabfecw\tabfewc\tabfwce\tabfwec\tabwcef\tabwcfe\tabwecf\tabwefc\tabwfce\tabwfec\tacbefw\tacbewf\tacbfew\tacbfwe\tacbwef\tacbwfe\tacebfw\tacebwf\tacefbw\tacefwb\tacewbf\tacewfb\tacfbew\tacfbwe\tacfebw\tacfewb\tacfwbe\tacfweb\tacwbef\tacwbfe\tacwebf\tacwefb\tacwfbe\tacwfeb\taebcfw\taebcwf\taebfcw\taebfwc\taebwcf\taebwfc\taecbfw\taecbwf\taecfbw\taecfwb\taecwbf\taecwfb\taefbcw\taefbwc\taefcbw\taefcwb\taefwbc\taefwcb\taewbcf\taewbfc\taewcbf\taewcfb\taewfbc\taewfcb\tafbcew\tafbcwe\tafbecw\tafbewc\tafbwce\tafbwec\tafcbew\tafcbwe\tafcebw\tafcewb\tafcwbe\tafcweb\tafebcw\tafebwc\tafecbw\tafecwb\tafewbc\tafewcb\tafwbce\tafwbec\tafwcbe\tafwceb\tafwebc\tafwecb\tawbcef\tawbcfe\tawbecf\tawbefc\tawbfce\tawbfec\tawcbef\tawcbfe\tawcebf\tawcefb\tawcfbe\tawcfeb\tawebcf\tawebfc\tawecbf\tawecfb\tawefbc\tawefcb\tawfbce\tawfbec\tawfcbe\tawfceb\tawfebc\tawfecb\tbacefw\tbacewf\tbacfew\tbacfwe\tbacwef\tbacwfe\tbaecfw\tbaecwf\tbaefcw\tbaefwc\tbaewcf\tbaewfc\tbafcew\tbafcwe\tbafecw\tbafewc\tbafwce\tbafwec\tbawcef\tbawcfe\tbawecf\tbawefc\tbawfce\tbawfec\tbcaefw\tbcaewf\tbcafew\tbcafwe\tbcawef\tbcawfe\tbceafw\tbceawf\tbcefaw\tbcefwa\tbcewaf\tbcewfa\tbcfaew\tbcfawe\tbcfeaw\tbcfewa\tbcfwae\tbcfwea\tbcwaef\tbcwafe\tbcweaf\tbcwefa\tbcwfae\tbcwfea\tbeacfw\tbeacwf\tbeafcw\tbeafwc\tbeawcf\tbeawfc\tbecafw\tbecawf\tbecfaw\tbecfwa\tbecwaf\tbecwfa\tbefacw\tbefawc\tbefcaw\tbefcwa\tbefwac\tbefwca\tbewacf\tbewafc\tbewcaf\tbewcfa\tbewfac\tbewfca\tbfacew\tbfacwe\tbfaecw\tbfaewc\tbfawce\tbfawec\tbfcaew\tbfcawe\tbfceaw\tbfcewa\tbfcwae\tbfcwea\tbfeacw\tbfeawc\tbfecaw\tbfecwa\tbfewac\tbfewca\tbfwace\tbfwaec\tbfwcae\tbfwcea\tbfweac\tbfweca\tbwacef\tbwacfe\tbwaecf\tbwaefc\tbwafce\tbwafec\tbwcaef\tbwcafe\tbwceaf\tbwcefa\tbwcfae\tbwcfea\tbweacf\tbweafc\tbwecaf\tbwecfa\tbwefac\tbwefca\tbwface\tbwfaec\tbwfcae\tbwfcea\tbwfeac\tbwfeca\tcabefw\tcabewf\tcabfew\tcabfwe\tcabwef\tcabwfe\tcaebfw\tcaebwf\tcaefbw\tcaefwb\tcaewbf\tcaewfb\tcafbew\tcafbwe\tcafebw\tcafewb\tcafwbe\tcafweb\tcawbef\tcawbfe\tcawebf\tcawefb\tcawfbe\tcawfeb\tcbaefw\tcbaewf\tcbafew\tcbafwe\tcbawef\tcbawfe\tcbeafw\tcbeawf\tcbefaw\tcbefwa\tcbewaf\tcbewfa\tcbfaew\tcbfawe\tcbfeaw\tcbfewa\tcbfwae\tcbfwea\tcbwaef\tcbwafe\tcbweaf\tcbwefa\tcbwfae\tcbwfea\tceabfw\tceabwf\tceafbw\tceafwb\tceawbf\tceawfb\tcebafw\tcebawf\tcebfaw\tcebfwa\tcebwaf\tcebwfa\tcefabw\tcefawb\tcefbaw\tcefbwa\tcefwab\tcefwba\tcewabf\tcewafb\tcewbaf\tcewbfa\tcewfab\tcewfba\tcfabew\tcfabwe\tcfaebw\tcfaewb\tcfawbe\tcfaweb\tcfbaew\tcfbawe\tcfbeaw\tcfbewa\tcfbwae\tcfbwea\tcfeabw\tcfeawb\tcfebaw\tcfebwa\tcfewab\tcfewba\tcfwabe\tcfwaeb\tcfwbae\tcfwbea\tcfweab\tcfweba\tcwabef\tcwabfe\tcwaebf\tcwaefb\tcwafbe\tcwafeb\tcwbaef\tcwbafe\tcwbeaf\tcwbefa\tcwbfae\tcwbfea\tcweabf\tcweafb\tcwebaf\tcwebfa\tcwefab\tcwefba\tcwfabe\tcwfaeb\tcwfbae\tcwfbea\tcwfeab\tcwfeba\teabcfw\teabcwf\teabfcw\teabfwc\teabwcf\teabwfc\teacbfw\teacbwf\teacfbw\teacfwb\teacwbf\teacwfb\teafbcw\teafbwc\teafcbw\teafcwb\teafwbc\teafwcb\teawbcf\teawbfc\teawcbf\teawcfb\teawfbc\teawfcb\tebacfw\tebacwf\tebafcw\tebafwc\tebawcf\tebawfc\tebcafw\tebcawf\tebcfaw\tebcfwa\tebcwaf\tebcwfa\tebfacw\tebfawc\tebfcaw\tebfcwa\tebfwac\tebfwca\tebwacf\tebwafc\tebwcaf\tebwcfa\tebwfac\tebwfca\tecabfw\tecabwf\tecafbw\tecafwb\tecawbf\tecawfb\tecbafw\tecbawf\tecbfaw\tecbfwa\tecbwaf\tecbwfa\tecfabw\tecfawb\tecfbaw\tecfbwa\tecfwab\tecfwba\tecwabf\tecwafb\tecwbaf\tecwbfa\tecwfab\tecwfba\tefabcw\tefabwc\tefacbw\tefacwb\tefawbc\tefawcb\tefbacw\tefbawc\tefbcaw\tefbcwa\tefbwac\tefbwca\tefcabw\tefcawb\tefcbaw\tefcbwa\tefcwab\tefcwba\tefwabc\tefwacb\tefwbac\tefwbca\tefwcab\tefwcba\tewabcf\tewabfc\tewacbf\tewacfb\tewafbc\tewafcb\tewbacf\tewbafc\tewbcaf\tewbcfa\tewbfac\tewbfca\tewcabf\tewcafb\tewcbaf\tewcbfa\tewcfab\tewcfba\tewfabc\tewfacb\tewfbac\tewfbca\tewfcab\tewfcba\tfabcew\tfabcwe\tfabecw\tfabewc\tfabwce\tfabwec\tfacbew\tfacbwe\tfacebw\tfacewb\tfacwbe\tfacweb\tfaebcw\tfaebwc\tfaecbw\tfaecwb\tfaewbc\tfaewcb\tfawbce\tfawbec\tfawcbe\tfawceb\tfawebc\tfawecb\tfbacew\tfbacwe\tfbaecw\tfbaewc\tfbawce\tfbawec\tfbcaew\tfbcawe\tfbceaw\tfbcewa\tfbcwae\tfbcwea\tfbeacw\tfbeawc\tfbecaw\tfbecwa\tfbewac\tfbewca\tfbwace\tfbwaec\tfbwcae\tfbwcea\tfbweac\tfbweca\tfcabew\tfcabwe\tfcaebw\tfcaewb\tfcawbe\tfcaweb\tfcbaew\tfcbawe\tfcbeaw\tfcbewa\tfcbwae\tfcbwea\tfceabw\tfceawb\tfcebaw\tfcebwa\tfcewab\tfcewba\tfcwabe\tfcwaeb\tfcwbae\tfcwbea\tfcweab\tfcweba\tfeabcw\tfeabwc\tfeacbw\tfeacwb\tfeawbc\tfeawcb\tfebacw\tfebawc\tfebcaw\tfebcwa\tfebwac\tfebwca\tfecabw\tfecawb\tfecbaw\tfecbwa\tfecwab\tfecwba\tfewabc\tfewacb\tfewbac\tfewbca\tfewcab\tfewcba\tfwabce\tfwabec\tfwacbe\tfwaceb\tfwaebc\tfwaecb\tfwbace\tfwbaec\tfwbcae\tfwbcea\tfwbeac\tfwbeca\tfwcabe\tfwcaeb\tfwcbae\tfwcbea\tfwceab\tfwceba\tfweabc\tfweacb\tfwebac\tfwebca\tfwecab\tfwecba\twabcef\twabcfe\twabecf\twabefc\twabfce\twabfec\twacbef\twacbfe\twacebf\twacefb\twacfbe\twacfeb\twaebcf\twaebfc\twaecbf\twaecfb\twaefbc\twaefcb\twafbce\twafbec\twafcbe\twafceb\twafebc\twafecb\twbacef\twbacfe\twbaecf\twbaefc\twbafce\twbafec\twbcaef\twbcafe\twbceaf\twbcefa\twbcfae\twbcfea\twbeacf\twbeafc\twbecaf\twbecfa\twbefac\twbefca\twbface\twbfaec\twbfcae\twbfcea\twbfeac\twbfeca\twcabef\twcabfe\twcaebf\twcaefb\twcafbe\twcafeb\twcbaef\twcbafe\twcbeaf\twcbefa\twcbfae\twcbfea\twceabf\twceafb\twcebaf\twcebfa\twcefab\twcefba\twcfabe\twcfaeb\twcfbae\twcfbea\twcfeab\twcfeba\tweabcf\tweabfc\tweacbf\tweacfb\tweafbc\tweafcb\twebacf\twebafc\twebcaf\twebcfa\twebfac\twebfca\twecabf\twecafb\twecbaf\twecbfa\twecfab\twecfba\twefabc\twefacb\twefbac\twefbca\twefcab\twefcba\twfabce\twfabec\twfacbe\twfaceb\twfaebc\twfaecb\twfbace\twfbaec\twfbcae\twfbcea\twfbeac\twfbeca\twfcabe\twfcaeb\twfcbae\twfcbea\twfceab\twfceba\twfeabc\twfeacb\twfebac\twfebca\twfecab\twfecba\tcost : 107us\n"
     ]
    }
   ],
   "source": [
    "// 字典序排列\n",
    "#include <iostream>\n",
    "#include <algorithm>\n",
    "#include <chrono>\n",
    "void CallAllPermutation(char* perm, int from, int to){\n",
    "    auto next_permutation = [](char* perm, int n){\n",
    "        int i = 0;\n",
    "        for(i = n - 2; (i >= 0) && (perm[i] >= perm[i+1]);i--){} //从右往左寻找第一个小于右边相邻元素的值\n",
    "        if(i < 0) return false; //该序列已经是一个递减序列\n",
    "        int k = 0;\n",
    "        for(k = n - 1; (k > i) && (perm[k] <= perm[i]); k--){} //在i的右边寻找第一个大于perm[i] 的元素\n",
    "        std::swap(perm[i], perm[k]);\n",
    "        std::reverse(perm + i + 1, perm + n);\n",
    "        return true;\n",
    "    };\n",
    "    std::sort(perm + from, perm + to + 1);// 拿到开始的递增序列，否则需要实现 last_permutaion 序列\n",
    "    std::cout << perm<<\"\\t\";\n",
    "    for(;;){\n",
    "        bool r = next_permutation(perm, to + 1);\n",
    "        if(r){\n",
    "            std::cout <<perm<<\"\\t\";\n",
    "        }else{\n",
    "            break;\n",
    "        }\n",
    "    }\n",
    "}\n",
    "auto start = std::chrono::system_clock::now();\n",
    "char arr[] = \"bcawef\";\n",
    "CallAllPermutation(arr, 0, 5);\n",
    "auto end   = std::chrono::system_clock::now();\n",
    "auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);\n",
    "std::cout <<  \"cost : \" << double(duration.count()) << \"us\" << std::endl;"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++14",
   "language": "C++14",
   "name": "xcpp14"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
